package cn.tedu.front.search.controller;

import cn.tedu.common.pojo.vo.PageData;
import cn.tedu.common.web.JsonResult;
import cn.tedu.front.search.pojo.param.SearchKeywordsParam;
import cn.tedu.front.search.pojo.po.CompanyPO;
import cn.tedu.front.search.pojo.po.JobSimplePO;
import cn.tedu.front.search.pojo.vo.SearchJobVO;
import cn.tedu.front.search.service.ICompanyService;
import cn.tedu.front.search.service.IJobService;
import cn.tedu.front.search.service.ISearchJobService;
import cn.tedu.front.search.service.impl.CompanyService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/search")
@Api(tags = "搜索功能")
@Slf4j
public class SearchController {
    @Autowired
    private ICompanyService companyService;
    @Autowired
    private IJobService jobService;
    @Autowired
    private ISearchJobService searchJobService;

    @GetMapping("/jobList/{searchKeywordsParam}")
    @ApiOperation(value = "根据关键搜索词查工作列表")
    @ApiOperationSupport(order = 403)
    public JsonResult searchJobList(@PathVariable SearchKeywordsParam searchKeywordsParam){
        log.info(""+searchKeywordsParam+"!!!!!!!!!!!!!!!!!!!");
        List<SearchJobVO> searchJobVOS = searchJobService.select(searchKeywordsParam);
        return JsonResult.ok(searchJobVOS);

    }

    @GetMapping("/company/")
    @ApiOperation(value = "根据关键词搜索公司信息")
    @ApiOperationSupport(order = 400)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", value = "关键词", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "1", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", defaultValue = "1", paramType = "query", dataType = "int")
    }
            )
    public JsonResult searchListCompany(String keyword, Integer pageNum, Integer pageSize){
        PageData<CompanyPO> company = companyService.getCompany(keyword, pageNum, pageSize);
        return JsonResult.ok(company);

    }
    @GetMapping("/job/{jobName}")
    @ApiOperation(value = "根据关键词搜索职位信息")
    @ApiOperationSupport(order = 401)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword", value = "关键词", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "pageNum", value = "页码", defaultValue = "1", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", defaultValue = "1", paramType = "query", dataType = "int")
    }
    )
    public JsonResult searchListJob(@RequestBody String keyword, Integer pageNum, Integer pageSize){
        PageData<JobSimplePO> job = jobService.getJob(keyword, pageNum, pageSize);
        return JsonResult.ok(job);

    }
}
